﻿using System.Collections.Generic;
using System.Linq;

namespace Rosetta.Default.AddIns
{
    public sealed class RangeConverter : Converter
    {
        // TODO: Other type of ranges, uint/short/byte/string/...

        #region Constructors

        public RangeConverter()
            : base("Range Converter")
        {
            Add<char, char, IEnumerable<char>>("GetCharRange", GetCharRange, "begin", "end");
            Add<int, int, IEnumerable<int>>("GetInt32Range", GetInt32Range, "start", "count");
        }

        #endregion

        #region Class Methods

        private static IEnumerable<char> GetCharRange(char begin, char end)
        {
            if (begin < end)
            {
                for (char c = begin; c <= end; c++)
                {
                    yield return c;
                }
            }
            else
            {
                for (char c = begin; c >= end; c--)
                {
                    yield return c;
                }
            }
        }

        private static IEnumerable<int> GetInt32Range(int start, int count)
        {
            return Enumerable.Range(start, count);
        }

        #endregion
    }
}